﻿@using GMailLabelCleanup.Core.Utilities
@model GMailLabelCleanup.Core.ViewModels.Filters.EditViewModel
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)

        <div class="form-group">
            @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "initialFocus form-control no-resize input-double-width", @rows = 3 } })
                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <h4>Criteria</h4>
                <h5>@Html.ValidationMessageFor(model => model.CriteriaProperties, "", new { @class = "text-danger" })</h5>
            </div>
        </div>
        <div class="row">
            @for (int i = 0; i < Model.CriteriaProperties.Count; i++)
            {
                @Html.Partial("_EditFilterPropertyPartial", Model.CriteriaProperties[i], "CriteriaProperties[" + i.ToString() + "]");
            }
        </div>
        <div class="row">
            <div class="col-lg-12">
                <h4>Actions</h4>
                <h5>@Html.ValidationMessageFor(model => model.ActionProperties, "", new { @class = "text-danger" })</h5>
            </div>
        </div>
        <div class="row">
            @for (int i = 0; i < Model.ActionProperties.Count; i++)
            {
                @Html.Partial("_EditFilterPropertyPartial", Model.ActionProperties[i], "ActionProperties[" + i.ToString() + "]");
            }
        </div>
        <div class="form-group">
            <div class="col-md-12">
                <input type="submit" value="Save" class="btn btn-default" />
            </div>
        </div>
    </div>
}

@Html.AddPartialScript(0,
    @<script type="text/javascript">
        $(function () {
            $('.IsIncluded').each(function () {
                if (this.checked) {
                    $(this).closest('div .panel').removeClass('panel-default');
                    $(this).closest('div .panel').addClass('panel-primary');
                }
                else {
                    $(this).closest('div .panel').removeClass('panel-primary');
                    $(this).closest('div .panel').addClass('panel-default');
                }
            });
            $('.IsIncluded').click(function () {
                if (this.checked) {
                    $(this).closest('div .panel').removeClass('panel-default');
                    $(this).closest('div .panel').addClass('panel-primary');
                }
                else {
                    $(this).closest('div .panel').removeClass('panel-primary');
                    $(this).closest('div .panel').addClass('panel-default');
                }
            });
        });
    </script>
    )
